package com.samphanie.auiu.biz.notice

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.samphanie.auiu.BuildConfig
import com.samphanie.auiu.common.ui.component.base.BaseViewModel
import com.samphanie.auiu.http.api.profileApiService
import com.samphanie.auiu.library.restful.AuiuCallback
import com.samphanie.auiu.library.restful.AuiuResponse
import com.samphanie.auiu.model.CourseNotice

/**
 * @author ZSY
 */
class NoticeListViewModel : BaseViewModel() {

    fun queryCourseNotice(): LiveData<CourseNotice?> {
        val courseNotice = MutableLiveData<CourseNotice?>()
        profileApiService().notice().enqueue(object : AuiuCallback<CourseNotice> {
            override fun onSuccess(response: AuiuResponse<CourseNotice>) {
                if (response.successful() && response.data != null) {
                   courseNotice.postValue(response.data)
                } else {
                    courseNotice.postValue(null)
                }
            }

            override fun onFailed(throwable: Throwable) {
                courseNotice.postValue(null)
                if (BuildConfig.DEBUG) {
                    throwable.printStackTrace()
                }
            }
        })

        return courseNotice
    }
}